#include "apue.h"
#include <stdio.h>
#include <time.h>
#include <limits.h>

int main(void) {
    time_t t;
    time_t max;

    struct tm *t_tm;
    
    char datestr[64];

    time(&t);
    max= ((long)INT_MAX) * 366 * 24 * 3600; // 365 是可以解析的，366 则会超过最后 tm_year int 类型的最大值，因为润年润秒的关系
    // max= LONG_MAX;

    printf("current timestamp %ld\n", t);
    printf("maximum timestamp %ld\n", max);

    if ((t_tm= localtime(&t)) == NULL)
        err_sys("localtime for t failed");

    printf("max year = %d\n", INT_MAX);
    if (strftime(datestr, 64, "%c %z", t_tm) == 0)
        err_sys("strftime for t failed");

    printf("current time is : %s\n", datestr);

    if ((t_tm= localtime(&max)) == NULL)
        err_sys("localtime for max failed");

    printf("max year = %d\n", t_tm->tm_year);

    if (strftime(datestr, 64, "%c %z", t_tm) == 0)
        err_sys("strftime for max failed");

    printf("current time is : %s\n", datestr);
}
